/********************************************************************************
    Author :
********************************************************************************/

/********************************************************************************
    Include Files :
********************************************************************************/
#include "extern.h"
	#include "IoToLight.h"
#include "alloc.h"
	#include "Light.h"
/********************************************************************************
    Defination :
********************************************************************************/

/********************************************************************************
    Comment : The description of defination
********************************************************************************/

/********************************************************************************
    Type name :
********************************************************************************/

/********************************************************************************
    Comment : The description of type name
********************************************************************************/

/********************************************************************************
    Private variables :
********************************************************************************/

/********************************************************************************
    Comment : The description of private variables
********************************************************************************/
PRIVATE enuBrightnessLevel enuRedLevel = ENU_LEVEL_OFF;
PRIVATE enuBrightnessLevel enuGreenLevel = ENU_LEVEL_OFF;
PRIVATE enuBrightnessLevel enuLockLevel = ENU_LEVEL_OFF;

/********************************************************************************
    Comment : The description of private variables
********************************************************************************/
PRIVATE enuSelectLight enuSelectedLight = ENU_SELECT_LIGHT_RED;

/********************************************************************************
    Private function declaration :
********************************************************************************/

/********************************************************************************
    Public function :
********************************************************************************/

/********************************************************************************
    Description :
        Increase the brightness of light
********************************************************************************/
PUBLIC FUNC(void,LIGHT_CODE) Light_vidIncreaseBrightness(enuChangeableLight enuLight)
{
	enuBrightnessLevel enuLevel = ENU_LEVEL_OFF;
	switch(enuLight)
	{
		case ENU_RED_LGIHT:
			enuLevel = enuRedLevel;
			break;
		case ENU_GREEN_LGIHT:
			enuLevel = enuGreenLevel;
			break;
		case ENU_LOCK_LGIHT:
			enuLevel = enuLockLevel;
			break;
		default:
			break;
	}
	if(enuLevel > MIN_LEVEL)
	{
		enuLevel--;
	}
	else
	{

	}
	switch(enuLight)
	{
		case ENU_RED_LGIHT:
			enuRedLevel = enuLevel;
			Light_vidSetBrightness(ENU_RED_LGIHT,enuLevel);
			break;
		case ENU_GREEN_LGIHT:
			enuGreenLevel = enuLevel;
			Light_vidSetBrightness(ENU_GREEN_LGIHT,enuLevel);
			break;
		case ENU_LOCK_LGIHT:
			enuLockLevel = enuLevel;
			Light_vidSetBrightness(ENU_LOCK_LGIHT,enuLevel);
			break;
		default:
			break;
	}
}

/********************************************************************************
    Description :
        Decrease the brightness of light
********************************************************************************/
PUBLIC FUNC(void,LIGHT_CODE) Light_vidDecreaseBrightness(enuChangeableLight enuLight)
{
	enuBrightnessLevel enuLevel = ENU_LEVEL_OFF;
	switch(enuLight)
	{
		case ENU_RED_LGIHT:
			enuLevel = enuRedLevel;
			break;
		case ENU_GREEN_LGIHT:
			enuLevel = enuGreenLevel;
			break;
		case ENU_LOCK_LGIHT:
			enuLevel = enuLockLevel;
			break;
		default:
			break;
	}
	if(enuLevel < MAX_LEVEL)
	{
		enuLevel++;
	}
	else
	{

	}
	switch(enuLight)
	{
		case ENU_RED_LGIHT:
			enuRedLevel = enuLevel;
			Light_vidSetBrightness(ENU_RED_LGIHT,enuLevel);
			break;
		case ENU_GREEN_LGIHT:
			enuGreenLevel = enuLevel;
			Light_vidSetBrightness(ENU_GREEN_LGIHT,enuLevel);
			break;
		case ENU_LOCK_LGIHT:
			enuLockLevel = enuLevel;
			Light_vidSetBrightness(ENU_LOCK_LGIHT,enuLevel);
			break;
		default:
			break;
	}
}

/********************************************************************************
    Description :
        Get the selected light
********************************************************************************/
PUBLIC FUNC(enuSelectLight,LIGHT_CODE) Light_enuGetSelectLight(void)
{
	return enuSelectedLight;
}

/********************************************************************************
    Description :
        Set the selected light
********************************************************************************/
PUBLIC FUNC(void,LIGHT_CODE) Light_vidSetSelectLight(enuSelectLight enuLight)
{
	enuSelectedLight = enuLight;
	if(enuLight == ENU_SELECT_LIGHT_RED)
	{
		IoHwAb_vidPullUpPin(ENU_WRITE_SELECT_LIGHT);
	}
	else
	{
		IoHwAb_vidPullDownPin(ENU_WRITE_SELECT_LIGHT);
	}
}
/********************************************************************************
    Description :
        Set the brightness of light
********************************************************************************/
PUBLIC FUNC(void,LIGHT_CODE) Light_vidSetBrightness(enuChangeableLight enuLight,enuBrightnessLevel enuLevel)
{
	switch(enuLight)
	{
		case ENU_RED_LGIHT:
			IoHwAb_vidUpdateBrightness(enuLevel,ENU_RED_LIGHT);
			break;
		case ENU_GREEN_LGIHT:
			IoHwAb_vidUpdateBrightness(enuLevel,ENU_GREEN_LIGHT);
			break;
		case ENU_LOCK_LGIHT:
			IoHwAb_vidUpdateBrightness(enuLevel,ENU_YELLOW_LOCK);
			break;
		default:
			break;
	}
}
/********************************************************************************
    Description :
        Get the brightness of light
********************************************************************************/
PUBLIC FUNC(enuBrightnessLevel,LIGHT_CODE) Light_enuGetBrightness(enuChangeableLight enuLight)
{
	enuBrightnessLevel enuLevel = ENU_LEVEL_OFF;
	switch(enuLight)
	{
		case ENU_RED_LGIHT:
			enuLevel = enuRedLevel;
			break;
		case ENU_GREEN_LGIHT:
			enuLevel = enuGreenLevel;
			break;
		case ENU_LOCK_LGIHT:
			enuLevel = enuLockLevel;
			break;
		default:
			break;
	}
	return enuLevel;
}

/********************************************************************************
    Description :
        Get the value of ADC
********************************************************************************/
PUBLIC FUNC(enuBrightnessLevel,LIGHT_CODE) Light_enuGetAdcValue(enuSelectLight enuLight)
{
	enuBrightnessLevel enuLevel = ENU_LEVEL_OFF;
	switch(enuLight)
	{
		case ENU_SELECT_LIGHT_RED:
			enuLevel = IoHwAb_enuGetRedAdcValue();
			break;
		case ENU_SELECT_LIGHT_GREEN:
			enuLevel = IoHwAb_enuGetGreenAdcValue();
			break;
		default:
			break;
	}
	return enuLevel;
}

/********************************************************************************
    Description :
        Set the brightness of light by ADC
********************************************************************************/
PUBLIC FUNC(void,LIGHT_CODE) Light_vidSetAdcValue(enuSelectLight enuLight)
{
	enuBrightnessLevel enuLevel = ENU_LEVEL_OFF;
	switch(enuLight)
	{
		case ENU_SELECT_LIGHT_RED:
			enuLevel = Light_enuGetAdcValue(ENU_SELECT_LIGHT_RED);
			Light_vidSetBrightness(ENU_RED_LGIHT,enuLevel);
			break;
		case ENU_SELECT_LIGHT_GREEN:
			enuLevel = Light_enuGetAdcValue(ENU_SELECT_LIGHT_GREEN);
			Light_vidSetBrightness(ENU_GREEN_LGIHT,enuLevel);
			break;
		default:
			break;
	}
}

/********************************************************************************
    Description :
        Update the light about lock
********************************************************************************/
PUBLIC FUNC(void,LIGHT_CODE) Light_vidUpdateLockLight(boolean bIsLock)
{
	if(bIsLock == TRUE)
	{
		IoHwAb_vidUpdateBrightness(MIN_LEVEL,ENU_YELLOW_LOCK);
	}
	else
	{
		IoHwAb_vidUpdateBrightness(MAX_LEVEL,ENU_YELLOW_LOCK);
	}
	
}


/********************************************************************************
    Private function :
********************************************************************************/

/********************************************************************************
    Description :
        The description of this function
********************************************************************************/
